import { Component, OnInit } from '@angular/core';
import { MerchantcashrecordService } from '../../service/merchantcashrecord.service';
import { MerchantinfoService } from '../../service/merchantinfo.service';
import { NzMessageService } from 'ng-zorro-antd';
import { CommonService } from 'src/app/service/common.service';
import { ComponentBasic } from '../../app.component';
import { RoleRight } from '../../../kalend';
import { Router, ActivatedRoute } from '@angular/router';
@Component({
  selector: 'app-merchantinfo',
  templateUrl: './agentmerchantlist.component.html',
  styleUrls: ['./agentmerchantlist.component.scss'],
  providers: [MerchantcashrecordService, CommonService, MerchantinfoService]
})
export class AgentmerchantlistComponent extends ComponentBasic implements OnInit {
  loading = true;
  pageIndex = 1;
  pageSize = 15;
  total = 1;
  doc: any = {};
  dataSet = [];
  sdate: any;
  edate: any;
  iscontact: any;
  remarks: any;
  //提现金额
  cashmoney: any;
  isVisible = false;
  isEditVisible = false;
  isOkLoading = false;
  LoginUser = RoleRight.getStorage();
  statuslist = [{ key: null, value: '全部' }, { key: '1', value: '已联系' }, { key: '0', value: '未联系' }];
  constructor(private merchantinfoService: MerchantinfoService, private router: Router, private merchantcashrecord: MerchantcashrecordService, private msg: NzMessageService, private commonservice: CommonService) {
    super();
    super.setLayout(true, true);
  }

  ngOnInit() {

    this.searchData();
  }
  searchData(reset: boolean = false): void {
    this.loading = true;
    this.merchantinfoService.querybyagent({
      offset: this.pageIndex,
      limit: this.pageSize,
      userid: this.LoginUser._id
    }).then((res) => {
      this.loading = false;
      this.total = res.total;
      this.dataSet = res.rows;
    });
  }

  edit(id): void {
    this.isEditVisible = true;
    this.merchantinfoService.queryone({ _id: id }).then((res) => {
      this.doc = res;
    });

  }


  AgentMerchantWineManage(id): void {
    let navurl = "manage/agentmerchantwinemanage/" + id;
    this.router.navigate([navurl]);
  }

  crsh(id): void {
    this.isVisible = true;
    this.merchantinfoService.queryone({ _id: id }).then((res) => {
      this.doc = res;
    });

  }

  SellteR(id): void {
    let navurl = "salesmanage/settlementrecordsMid/" + id;
    this.router.navigate([navurl]);
  }

  //确认编辑修改完毕
  handleEditOk(): void {


  }


  //确认提现完毕
  handleOk(): void {
    if (parseFloat(this.cashmoney).toString() === 'NaN') {
      this.msg.warning('请输入正确提现金额！');
      return;
    }
    if (Number(this.cashmoney) < 10) {
      this.msg.warning('提现金额不得低于10元！');
      return;
    }
    if (this.doc.balance < this.cashmoney) {
      this.msg.warning('提现金额不能大于余额！');
      return;
    }

    let parm = {
      totalcase: this.cashmoney,
      BankCardNo: this.doc.BankCardNumber,
      merchantid: this.doc._id,
      Bank: this.doc.Bank,
      merchantname: this.doc.name
    }
    this.merchantcashrecord.create(parm).then((res) => {
      this.searchData();
      this.isVisible = false;
      this.doc = {};
    });

  }

  handleCancel(): void {
    this.isVisible = false;
    this.doc = {};
  }

  edithandleCancel(): void {
    this.isEditVisible = false;
  }
}
